package org.force4spring.query;

public class OrderExpression implements Expression {
	private Expression field;
	private boolean descending = false;
	
	protected OrderExpression(Expression field, boolean descending) {
		this.field = field;
		this.descending = descending;
	}
	
	public static OrderExpression asc(Expression field) {
		return new OrderExpression(field, false);
	}
	
	public static OrderExpression desc(Expression field) {
		return new OrderExpression(field, true);
	}
	
	/**
	 * @see org.force4spring.query.Expression#buildSOQL()
	 */
	public String buildSOQL() {
		StringBuffer soql = new StringBuffer();
		soql.append(field.buildSOQL()).append(" ");
		if (descending) {
			soql.append("DESC");
		} else {
			soql.append("ASC");
		}
		return soql.toString();
	}

}
